package com.demo.springbootjobcron.config;

import com.demo.springbootjobcron.job.TestJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Hanson
 * @date 2022/9/7 10:26
 */
@Configuration
public class QuartzConfig {
    @Value("${vccp.QuartzConfig.OTAUpgradeJobCron}")
    private String OTAUpgradeJobCron;

    @Bean
    public Trigger testDetailTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(testJobDetail())
                .withIdentity("testDetailTrigger", "testTri")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(OTAUpgradeJobCron))    //[秒] [分] [小时] [日] [月] [周] [年]
                .build();
    }

    @Bean
    public JobDetail testJobDetail() {
        return JobBuilder.newJob(TestJob.class).storeDurably()
                .withIdentity("testJob", "testJob")
                .build();
    }
}
